package bitOperation;

import org.junit.Test;

/*
 *@description 数字范围按位与
 *@author hkfan
 *@version 1.0
 *@create 2025/6/23 16:50
 */
public class LeetCode_201 {

    @Test
    public void test(){
        System.out.println(rangeBitwiseAnd(2147483646,2147483647));
    }

    /**
     * @description 寻找公共前缀，其余位全为0
     * @author hkfan
     * @time 2025/6/26 15:11
     */
    public int rangeBitwiseAnd(int left, int right) {
        int res = Integer.MAX_VALUE;
        int count =0;
        while (left!=right){
            left=left>>1;
            right=right>>1;
            count++;
        }
        return res&(left<<count);
    }

}
